package org.nashua.tt151;

public final class LED {
	public static final LED AMBER = new LED("Amber", /*R*/200, 255, false, /*G*/0, 255, false, /*B*/0, 255, false, 
			/*H*/0, 255, false, /*S*/0, 255, false, /*V*/0, 255, false); 
	public static final LED BLUE = new LED("Blue", /*R*/0, 255, false, /*G*/0, 255, false, /*B*/230, 255, false,
			/*H*/125, 160, false, /*S*/0, 255, false, /*V*/0, 255, false);
	public static final LED GREEN = new LED("Green", /*R*/0, 50, false, /*G*/0, 255, false, /*B*/58, 255, false,
			/*H**/0, 255, false, /*S*/0, 255, false, /*V*/0, 255, false);
	public static final LED RED = new LED("Red", /*R*/200, 255, false, /*G*/0, 255, false, /*B*/0, 255, false,
			/*H*/110, 190, true, /*S*/0, 255, false, /*V*/0, 255, false);
	public static LED get(String color) {
		for (LED l:new LED[]{AMBER, BLUE, GREEN, RED}) {
			if (l.toString().equalsIgnoreCase(color)) {
				return l;
			}
		}
		return RED;
	}
	private int bMax;
	private int bMin;
	private boolean bRev;
	private int gMax;
	private int gMin;
	private boolean gRev;
	private int hMax;
	private int hMin;
	private boolean hRev;
	private int rMax;
	private int rMin;
	private boolean rRev;
	private int sMax;
	private int sMin;
	private boolean sRev;
	private int vMax;
	private int vMin;
	private boolean vRev;
	private String name;
	public LED(String name, int rMin, int rMax, boolean rRev, int gMin, int gMax, boolean gRev, int bMin, int bMax, boolean bRev,
			int hMin, int hMax, boolean hRev, int sMin, int sMax, boolean sRev, int vMin, int vMax, boolean vRev) {
		this.name = name;
		this.rMin = rMin;
		this.rMax = rMax;
		this.rRev = rRev;
		this.gMin = gMin;
		this.gMax = gMax;
		this.gRev = gRev;
		this.bMin = bMin;
		this.bMax = bMax;
		this.bRev = bRev;
		this.hMin = hMin;
		this.hMax = hMax;
		this.hRev = hRev;
		this.sMin = sMin;
		this.sMax = sMax;
		this.sRev = sRev;
		this.vMin = vMin;
		this.vMax = vMax;
		this.vRev = vRev;
	}
	public boolean testPixel(int r, int g, int b, int h, int s, int v) {
		/*return r<=rMax && r>=rMin && g<=gMax && g>=gMin && b<=bMax && b>=bMin // RGB Check
				&& h<=hMax && h>=hMin && s<=sMax && s>=sMin && v<=vMax && v>=vMin; // HSV Check*/
		if ((!rRev && r<=rMax && r>=rMin) || (rRev && (r>=rMax || r<=rMin))) {
			if ((!gRev && g<=gMax && g>=gMin) || (gRev && (g>=gMax || g<=gMin))) {
				if ((!bRev && b<=bMax && b>=bMin) || (bRev && (b>=bMax || b<=bMin))) {
					if ((!hRev && h<=hMax && h>=hMin) || (hRev && (h>=hMax || h<=hMin))) {
						if ((!sRev && s<=sMax && s>=sMin) || (sRev && (s>=sMax || s<=sMin))) {
							if ((!vRev && v<=vMax && v>=vMin) || (vRev && (v>=vMax || v<=vMin))) {
								return true;
							}
						}
					}
				}
			}
		}
		return false;
	}
	public String toString() {
		return name;
	}
}
